package com.wuxiaofan.product.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuxiaofan.product.entity.Attr;
import com.wuxiaofan.product.entity.custom.AttrCustom;
import com.wuxiaofan.product.mapper.AttrMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wuxiaofan.product.client.Idgenerator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

@Service
public class AttrService {
    @Autowired
    private AttrMapper pmsAttrMapper;
    @Resource
    private Idgenerator idgenerator;

    public Page<AttrCustom> findPageByAttrTypeAndCategoryId(String attrType,String categoryId,Page page){
        Map paraMap = new HashMap();
        paraMap.put("catelogId",categoryId);
        paraMap.put("attrType",attrType);
        Page<AttrCustom> attrCustomPage = findByMap(paraMap,page);
        return attrCustomPage;
    }


    public Attr findById(String id){
        return pmsAttrMapper.selectById(id);
    }

    public AttrCustom findCountByMap(Map paraMap){
        return pmsAttrMapper.findCountByMap(paraMap);
    }

    public AttrCustom findGroupByMap(Map paraMap){
        return pmsAttrMapper.findGroupByMap(paraMap);
    }

    public List<AttrCustom> findByMap(Map paraMap){
        return pmsAttrMapper.findByMap(paraMap);
    }

    public Page<AttrCustom> findByMap(Map paraMap, Page page){
        return page.setRecords(pmsAttrMapper.findByMap(paraMap,page));
    }


    public void updateMapById(Map paraMap){
        pmsAttrMapper.updateMapById(paraMap);
    }
    public void delById(String id){
        pmsAttrMapper.deleteById(id);
    }

    public Attr save(Attr pmsAttr){
        pmsAttr.setAttrId(idgenerator.getId());
        pmsAttrMapper.insert(pmsAttr);
        return pmsAttr;
    }

}
